﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YhmOA.Common;
using System.Text;

namespace YhmOA.Framework
{
    public partial class Left : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            string topMenu = Request.QueryString["xml"] ?? "个人办公";
            Dictionary<string, object> dic = MenuConfig.GetLeftMenu(topMenu);
            StringBuilder builder = new StringBuilder();
            //便利当前节点下的所有低级节点
            foreach (string leftTop in dic.Keys)
            {
                string a = leftTop;
                object o = dic[a];
                string typeName = o.GetType().Name;
                if (typeName == "List`1")
                {
                    builder.AppendLine("<div class=\"csswai\">");
                    builder.AppendLine("\t<div class=\"cssmenumouseout\">");
                    builder.AppendLine("\t\t<dd>&nbsp;</dd>");
                    builder.AppendLine("\t\t<dt></dt>");
                    builder.AppendLine("\t\t<dt>" + leftTop + "</dt>");
                    builder.AppendLine("\t\t<div style=\"clear:both\"></div>");
                    builder.AppendLine("\t</div>");
                    foreach (MenuInfo menuInfo in dic[leftTop] as List<MenuInfo>)
                    {
                        builder.AppendLine("\t<dt onclick=\"RoleVerification('" + menuInfo.Text + "');\" id=\"__" + menuInfo.Text + "\" class=\"cssmenumouseoutlist\" url=\"" + menuInfo.Url + "\" type=\"" + menuInfo.Type + "\">");
                        builder.AppendLine("\t\t<img onerror=\"javascript:this.src='/Framework/images/new_tab.gif'\" src=\"/Framework/images/" + menuInfo.Img + "\" style=\"vertical-align:middle;\"/>");
                        builder.AppendLine("\t\t<span>" + menuInfo.Text + "</span>");
                        builder.AppendLine("\t</dt>");
                    }
                    builder.AppendLine("</div>");
                }
                if (typeName == "Dictionary`2")
                {
                    builder.AppendLine("<div class=\"csswai\">");
                    builder.AppendLine("\t<div class=\"cssmenumouseout\">");
                    builder.AppendLine("\t\t<dd>&nbsp;</dd>");
                    builder.AppendLine("\t\t<dt></dt>");
                    builder.AppendLine("\t\t<dt>" + leftTop + "</dt>");
                    builder.AppendLine("\t\t<div style=\"clear:both\"></div>");
                    builder.AppendLine("\t</div>");
                    builder.AppendLine("\t<div>");
                    foreach (string top in (dic[leftTop] as Dictionary<string, List<MenuInfo>>).Keys)
                    {
                        builder.AppendLine("\t\t<div class=\"cssli\">");
                        builder.AppendLine("\t\t\t<div class=\"cssmenumouseout\">");
                        builder.AppendLine("\t\t\t\t<dd>&nbsp;</dd>");
                        builder.AppendLine("\t\t\t\t<dt></dt>");
                        builder.AppendLine("\t\t\t\t<dt>"+top+"</dt>");
                        builder.AppendLine("\t\t\t\t<div style=\"clear:both\"></div>");
                        builder.AppendLine("\t\t\t</div>");
                        foreach (MenuInfo menuInfo in ((dic[leftTop] as Dictionary<string, List<MenuInfo>>)[top]) as List<MenuInfo>)
                        {
                            builder.AppendLine("\t\t\t<dt  onclick=\"RoleVerification('" + menuInfo.Text + "');\" id=\"__" + menuInfo.Text + "\" class=\"cssmenumouseoutlist\" url=\"" + menuInfo.Url + "\" type=\"" + menuInfo.Type + "\">");
                            builder.AppendLine("\t\t\t\t<img onerror=\"javascript:this.src='/Framework/images/new_tab.gif'\" src=\"/Framework/images/" + menuInfo.Img + "\" style=\"vertical-align:middle;\"/>");
                            builder.AppendLine("\t\t\t\t<span>" + menuInfo.Text + "</span>");
                            builder.AppendLine("\t\t\t</dt>");
                        }
                        builder.AppendLine("\t\t</div>");
                    }
                    builder.AppendLine("\t</div>");
                    builder.AppendLine("</div>");
                }
            }
            this.ltContent.Text = builder.ToString();
        }

        [AjaxMethod]
        public void RoleVerification(string name)
        {
            bool flag = true;
            if (name == "我的桌面")
            {
                flag = false;
            }
            if (flag)
            {
                //MessageBox("您有权限");
                ExecClientScript("MainBodyUrl('__" + name + "');");
            }
            else
            {
                MessageBox("您没有权限");
            }
        }
    }
}